# PHP

Languine supports PHP localization files using a modern array-based format. Perfect for PHP applications, it handles nested structures while maintaining type safety with strict types enabled.

---

## Setting Up

First, create a `languine.json` config file in your project root:

```json title="languine.json"
{
  "locale": {
    "source": "en",
    "targets": ["es", "fr", "de"]
  },
  "files": {
    "php": {
      "include": ["lang/[locale]/*.php"]
    }
  }
}
```

## File Format

Your PHP translation files should return an array. Here's an example structure:

```ts title="lang/en/common.php"
<?php

declare(strict_types=1);

return [
    'welcome' => 'Welcome to our app',
    'auth' => [
        'login' => 'Log in',
        'register' => 'Register',
        'forgot_password' => 'Forgot your password?'
    ],
    'errors' => [
        'not_found' => 'Page not found',
        'server_error' => 'Server error occurred'
    ]
];
```

`declare(strict_types=1)` is completely optional and is only used to ensure type safety.

## Translating

With your config set, run:

```bash
npx languine@latest translate
```

When you run this command, Languine will:

1. Parse your source PHP files (e.g., `lang/en/*.php`)
2. Detect new or modified translation strings
3. Generate translations for target languages
4. Create or update target language PHP files (e.g., `lang/sv/*.php`)
5. Preserve PHP structure and nesting
6. Maintain strict types declaration
7. Keep code formatting consistent
